<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>管理员操作</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/layui/dist/css/view.css}"/>
    <link rel="stylesheet" th:href="@{/layui/dist/css/layui.css}"  media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.min.css}">
</head>
<body class="layui-view-body">
<div class="layui-content">
    <div class="layui-page-header">
        <div class="pagewrap">
            <div class="pagewrap" style="height: 80px;">
                <div style="margin-left: 50px;margin-top: 30px;">
                    <font size="6">图书信息</font>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="form-box">
                    <form th:action="@{/bookList}" style="width: 1000px">
                        <div class="layui-form layui-form-item" style="float: left;">
                            <div class="layui-inline">
                                <div class="layui-form-mid">书籍名称:</div>
                                <div class="layui-input-inline" style="width: 120px;">
                                    <input type="text" autocomplete="off" class="layui-input" name="bookName">
                                </div>
                                <div class="layui-form-mid">出版社:</div>
                                <div class="layui-input-inline" style="width: 120px;">
                                    <input type="text" autocomplete="off" class="layui-input"  name="bookPublishers">
                                </div>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <div class="layui-form-mid">书籍类型:</div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <select  name="bookType">
                                        <option value="">请选择</option>
                                        <option th:selected="${bookType == '1'}" value="1">古典文学</option>
                                        <option th:selected="${bookType == '2'}" value="2">青春文学</option>
                                        <option th:selected="${bookType == '3'}" value="3">小说</option>
                                        <option th:selected="${bookType == '4'}" value="4">艺术</option>
                                        <option th:selected="${bookType == '5'}" value="5">文化</option>
                                        <option th:selected="${bookType == '6'}" value="6">历史</option>
                                        <option th:selected="${bookType == '7'}" value="7">经济</option>
                                    </select>
                                </div>
                                <button class="layui-btn layui-btn-blue" type="submit">查询</button>
                            </div>
                        </div>
                    </form>
                    <div style="width: 100px;float: left;margin-left: 250px">
                        <button class="layui-btn layui-btn-blue" onclick="addBook()">
                            <i class="layui-icon">&#xe654;</i>新增</button>
                    </div>
                    <div style="width: 100px;float: left;">
                        <button class="layui-btn layui-btn-blue" onclick="downloadfile()"> 导出信息</button>
                    </div>
                    <table class="layui-table">
                        <colgroup>
                            <col width="150">
                            <col width="130">
                            <col>
                        </colgroup>
                        <thead>
                        <tr>
                            <th>书籍编号</th>
                            <th>书籍名称</th>
                            <th>书籍类型</th>
                            <th>入库时间</th>
                            <th>出版社</th>
                            <th>书籍剩余量</th>
                            <th>作者</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="book:${list}">
                            <td th:text="${book.bookNumber}">书籍编号</td>
                            <td th:text="${book.bookName}">书籍姓名</td>
                            <td th:text="${book.bookType} == '1' ? '古典文学'
                                : (${book.bookType} == '2' ? '青春文学'
                                : (${book.bookType} == '3' ? '小说'
                                : (${book.bookType} == '4' ? '艺术'
                                : (${book.bookType} == '5' ? '文化'
                                : (${book.bookType} == '6' ? '历史' : '经济'
                                )
                                )
                                )
                                )
                                )
                                ">书籍类型</td>
                            <td th:text="${#dates.format(book.bookTime,'yyyy-MM-dd')}">入库时间</td>
                            <td th:text="${book.bookPublishers}">出版社</td>
                            <td th:text="${book.bookNum}">书籍剩余量</td>
                            <td th:text="${book.bookAuthor}">作者</td>
                            <td>
                                <button class="layui-btn layui-btn-sm" type="button" th:onclick="'showBookDetail(' +${book.bookNumber} + ')'">查看详情</button>
                                <button class="layui-btn layui-btn-sm layui-btn-danger" type="button" th:onclick="'deletefm(' +${book.bookNumber} + ')'">删除</button>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <!--分页导航-->
                    <div class="pagination center pagination-large pt-20" style="margin-left: 30%">
                        <div class="row text-center">
                            <div class="col-md-12">
                                <ul class="pagination">
                                    <li><a th:class="${currentPage eq 1 ? 'btn disabled' : '' }" href="javascript:;" th:href="@{/bookList(page=1,bookName=${bookName},bookPublishers=${bookPublishers},bookType=${bookType})}">首页</a></li>
                                    <li><a th:class="${currentPage eq 1 ? 'btn disabled' : '' }" href="javascript:void(0);" th:href="@{/bookList(page=${currentPage}-1,bookName=${bookName},bookPublishers=${bookPublishers},bookType=${bookType})}">&laquo;</a></li>

                                    <li th:class="${page eq currentPage} ? 'active' : ''" th:each="page:${#numbers.sequence(1,totalPage)}">
                                        <a href="javascript:void(0);" th:href="@{/bookList(page=${page},bookName=${bookName},bookPublishers=${bookPublishers},bookType=${bookType})}" th:text="${page}">1</a>
                                    </li>

                                    <li><a th:class="${currentPage eq totalPage ? 'btn disabled' : '' }" href="javascript:void(0);" th:href="@{/bookList(page=${currentPage}+1,bookName=${bookName},bookPublishers=${bookPublishers},bookType=${bookType})}">&raquo;</a></li>
                                    <li><a th:class="${currentPage eq totalPage ? 'btn disabled' : '' }" href="#" th:href="@{/bookList(page=${totalPage},bookName=${bookName},bookPublishers=${bookPublishers},bookType=${bookType})}" style="border: 1px solid #ddd;">尾页</a></li>
                                    <li><a style="border: 0px;margin-left: 0px;">当前页<span th:text="${currentPage}"></span>/<span th:text="${totalPage}"></span>总页</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script th:src="@{/layui/dist/layui.all.js}" charset="utf-8"></script>
<script th:src="@{/js/jquery.min.js}" charset="utf-8"></script>
<script>
    //弹出层 显示书籍详细信息
    function showBookDetail(bookNumber){
        layer.open({
            //layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
            type:2,
            title:"用户详细信息",
            area: ['80%','80%','left:126px'],
            content:'/booksystem/showBookDetail?bookNumber=' + bookNumber,

            end: function() {
                window.location.reload();
            }

        });

    }

    //询问层 删除书籍
    function deletefm(bookNumber) {
        //询问框
        layer.confirm('确认要删除？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            //发送ajax异步删除
            $.ajax({
                ////
                url : '/booksystem/deleteBook?bookNumber=' + bookNumber,
                method :'post',
                data : {bookNumber:bookNumber},
                success : function (data) {
                    layer.msg('删除成功', {icon: 1},function () {
                        //重新加载页面
                        layer.load(1);
                        window.location.reload(true);
                    });
                }
            })
        }, function(){
            // layer.alert("取消删除");
        });
    }

    //弹出层 添加图书
    function addBook(){
        layer.open({
            //layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
            type:2,
            title:"添加图书",
            area: ['80%','80%','left:126px'],
            content:'/booksystem/jumpToAddBook',

            end: function () {
                window.location.reload();
            }

        });

    }

    //导出信息
    function downloadfile() {
        window.location.href = "/booksystem/loadSysBook";
    }

</script>

</body>
</html>
